/*
 * @copyright fxsen <br/>
 * @date 2022/4/18 17:10 <br/>
 * @email <a href="mailto:fxsen@foxmail.com">
 * @author fxsen
 */
package com.fxsen.commons.web.core.task;

import com.fxsen.commons.sysmanager.core.entity.OperationLog;
import com.fxsen.commons.sysmanager.core.service.IOperationLogService;
import com.fxsen.commons.sysmanager.core.service.IRoleService;
import com.fxsen.commons.web.core.queue.OperationLogQueue;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * @author fxsen
 * @date 2022/4/18 17:10
 * @email <a href="mailto:fxsen@foxmail.com">
 */
//@Component
public class OperationLogTask {
    @Autowired
    private IOperationLogService operationLogService;
    @Autowired
    private IRoleService roleService;
//    @Scheduled(initialDelay=10000, fixedRate=60000)
    public void saveUserBehavior() {
        OperationLogQueue queue = OperationLogQueue.getInstance();
        try {
            List<OperationLog> list = new ArrayList<OperationLog>();
            OperationLog ub = null;
            for (int i = 0; i < 500; i++) {
                ub = queue.poll();
                if(ub == null){
                    break;
                }
                list.add(ub);
            }
            if(list.size() > 0){
                operationLogService.saveBatch(list);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
